$(document).ready(function(){
	
	$.ajax({
  		type: "post",
 		url: "hmk/getWukuType_getWukuType.action",
  		success:function(data){
  			$.each(data.typeList,function(i,n){
  				$("<option value="+n.tpyeId+">"+n.tpyeName+"</option>").appendTo('#goodTypeID');
			});
			
			//设置选中的select 			
			var typeID = $("#typeID").text();
			//alert(typeID);
			$("#goodTypeID option").each(function(){
				var v = $(this).attr("value");
				if(v==typeID){
					$(this).attr("selected","selected");
				}
			});
  		}
	});
	
	////////////////////////////
	$("#acceptForm").validate({
		submitHandler: function(form){   //表单提交句柄,为一回调函数，带一个参数：form  
            //form.submit();   //提交表单
     	var agkuID = $("#aidkuID").text();
		var typeID=$('#goodTypeID option:selected').val();
		var agkuName=$('#agkuNameID').val();
		var agkuUnit=$('#agkuUnitId').val();
		var agkuScale=$('#agkuScaleID').val();
		var agkuLocation=$('#agkuLocationID').val();
		var agkuLat=$('#agkuLatID').val();
		var agkuLng=$('#agkuLngID').val();
		
		$.ajax({
  			type: "post",
 			url: "hmk/saveAidGoodsKU_updateAGKU.action",
 			data:{
 				  agkuID1:agkuID,typeID1:typeID,agkuName1:agkuName,agkuUnit1:agkuUnit,agkuScale1:agkuScale,
 				  agkuLocation1:agkuLocation,agkuLat1:agkuLat,agkuLng1:agkuLng
 				 },
  			success:showData
		 });
		  
        },
		rules: {
			'goodTypeID':'required',
			'agkuNameID':'required',
			'agkuLocationID':'required',
			'agkuLatID':{
				required:false,
				digits:true
			},
			'agkuLngID':{
				required:false,
				digits:true
			},
			'agkuUnitId':'required'
			
		} ,
		messages: {
			'goodTypeID':'*必须选',
			'agkuNameID':'*必须选',
			'agkuLocationID':'*必须选',
			'agkuLatID':{
				required:'',
				digits:'数字'
			},
			'agkuLngID':{
				required:'',
				digits:'数字'
			},
			'agkuUnitId':'*必须选'
			
		}
	});
	
	//返回
	$("#back_Goodsku").click(function(){
		var content = $("#aidkuID").text();
		window.location.href="/ag/hmk/findOneAGKU_findOneAgku.action?agkuID1="+content;
	});
	
});

	function showData(data){
		if(data.ajaxRST=='1'){
			alert("更新成功！");
			var content = $("#aidkuID").text();
			window.location.href="/ag/hmk/findOneAGKU_findOneAgku.action?agkuID1="+content;
		}else{
			alert("更新失败！");
		}
	}